home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / p8fillp.c < prev    next >
Text File  |  1993-12-06  |  4KB  |  108 lines

  1. /**
  2.  ** P8FILLP.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p8.h"
  25. #include "memcopy.h"
  26. #include "bytedraw.h"
  27. #include "gmalloc.h"
  28.  
  29. void _GrP8FillPattern(int x,int y,int width,GrPattern *p)
  30. {
  31.     pixptr dst;
  32.  
  33.     if(width <= 0) return;
  34.     if(_GrP8UsePlanarMode) PLANAR_MODE_OFF();
  35.     x += CURC->gc_xoffset;
  36.     y += CURC->gc_yoffset;
  37.     dst = (pixptr)(CURC->gc_baseaddr + (y * CURC->gc_lineoffset) + x);
  38.     _ClrDir();
  39.     if(p->gp_ispixmap) {
  40.         int pattwdt = p->gp_pxp_width;
  41.         int optype  = C_OPER(p->gp_pxp_oper);
  42.         int cpysize = x % pattwdt;
  43.         pixptr srcline = (pixptr)(p->gp_pxp_source.gc_baseaddr +
  44.          ((y % p->gp_pxp_height) * p->gp_pxp_source.gc_lineoffset));
  45.         pixptr srcptr;
  46.  
  47.         if(p->gp_pxp_source.gc_onscreen) {
  48.         srcptr = (pixptr)_GrGetTempBuffer(pattwdt);
  49.         if(srcptr == NULL) return;
  50.         _SaveDS();
  51.         _RowCpyB(GETPAT,srcptr,srcline,pattwdt);
  52.         _RestoreDS();
  53.         srcline = srcptr;
  54.         }
  55.         srcptr  = srcline + cpysize;
  56.         cpysize = pattwdt - cpysize;
  57.         _SaveDS();
  58.         while(width > 0) {
  59.         if(cpysize > width) cpysize = width;
  60.         switch(optype) {
  61.             case C_XOR: _RowCpyXorB(X,dst,srcptr,cpysize); break;
  62.             case C_OR:  _RowCpyOrB(O,dst,srcptr,cpysize);  break;
  63.             case C_AND: _RowCpyAndB(A,dst,srcptr,cpysize); break;
  64.             default:    _RowCpyB(C,dst,srcptr,cpysize);       break;
  65.         }
  66.         width  -= cpysize;
  67.         dst    += cpysize;
  68.         srcptr  = srcline;
  69.         cpysize = pattwdt;
  70.         }
  71.         _RestoreDS();
  72.     }
  73.     else {
  74.         int bits = p->gp_bmp_data[y % p->gp_bmp_height];
  75.         int fgc  = p->gp_bmp_fgcolor;
  76.         int bgc  = p->gp_bmp_bgcolor;
  77.         int fgop = C_OPER(fgc);
  78.         int bgop = C_OPER(bgc);
  79.         int drawfg = _GrP8DrawTable[fgop] ^ (fgc &= C_SIGNIF);
  80.         int drawbg = _GrP8DrawTable[bgop] ^ (bgc &= C_SIGNIF);
  81.  
  82.         x &= 7;
  83.         bits = (bits << x) | ((bits & 0xff) >> (8 - x));
  84.         if(drawfg && drawbg && (fgop == bgop)) {
  85.         bgc |= ((fgc ^ bgc) << 8);
  86.         switch(fgop) {
  87.             case C_XOR: _PatternXor(dst,bits,width,bgc); return;
  88.             case C_OR:  _PatternOr(dst,bits,width,bgc);  return;
  89.             case C_AND: _PatternAnd(dst,bits,width,bgc); return;
  90.             default:    _PatternSet(dst,bits,width,bgc); return;
  91.         }
  92.         }
  93.         if(drawfg) switch(fgop) {
  94.         case C_XOR: _PattFGCXor(dst,bits,width,fgc); break;
  95.         case C_OR:  _PattFGCOr(dst,bits,width,fgc);  break;
  96.         case C_AND: _PattFGCAnd(dst,bits,width,fgc); break;
  97.         default:    _PattFGCSet(dst,bits,width,fgc); break;
  98.         }
  99.         if(drawbg) switch(bgop) {
  100.         case C_XOR: _PattBGCXor(dst,bits,width,bgc); break;
  101.         case C_OR:  _PattBGCOr(dst,bits,width,bgc);  break;
  102.         case C_AND: _PattBGCAnd(dst,bits,width,bgc); break;
  103.         default:    _PattBGCSet(dst,bits,width,bgc); break;
  104.         }
  105.     }
  106. }
  107.  
  108.